package com.iven.xie.es.entity;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * <p>
 * 返回结果
 * </p>
 *
 * @author iven.xie
 * @version 1.0
 * @since jdk1.8
 */
@Data
public class Result<T> {
    @ApiModelProperty(name = "是否成功")
    private boolean success = true;
    @ApiModelProperty(name = "状态")
    private Integer code;
    @ApiModelProperty(name = "信息")
    private String message;
    @ApiModelProperty(name = "结果集")
    private T data;

    public Result() {
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
        if (HttpStatus.OK.value() != code) {
            this.success = false;
        }
    }

    public Result(Integer code, T data) {
        this.code = code;
        this.data = data;
        if (HttpStatus.OK.value() != code) {
            this.success = false;
        }
    }

    public Result(boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public Result(boolean success, Integer code, String message, T data) {
        this.success = success;
        this.code = code;
        this.message = message;
        this.data = data;
    }
}
